/**
  ******************************************************************************
  * @author     Chris
  * @since      2024/7/12 22:23
  *
  * @file       hd_oled_font.h
  * @brief      Header file of Xxx hardware driver.
  *
  * @note       This file contains the Xxx object declaration.
  *
  * @warning    None.
  ******************************************************************************
  * Change Logs:
  *   Date          Author       Notes
  *   2024/7/12     Chris        the first version
  *
  ******************************************************************************
  */


#ifndef JLC_SKY_OLED_FONT_H
#define JLC_SKY_OLED_FONT_H

#include "hd_storage.h"

struct OLEDFontVtbl;

// Object properties
typedef struct {
    /**
     * The Storage is a interface that provide dot matrix data. Storage can be any kind of
     * storage device as long as it can provide the OLED dot matrix data we need.
     * eg. W25Qxx, EEPROM, Flash, SDCard, etc.
     */
    Storage *storage;
    /**
     * the font's encoding, 0, GBK; 1, UTF-8
     */
    uint8_t encoding;

    struct OLEDFontVtbl const *vptr;
} OLEDFont;

// Object virtual table
struct OLEDFontVtbl {
    /**
     * Get a Dot Matrix data from a storage(Flash, SD card, etc.) through the font code and its size.
     */
    uint8_t (*get_font_dot_matrix)(const OLEDFont *this, uint8_t *dotMatrix, const uint8_t *font,
                                   const uint8_t fontSize);
};

// Object constructor and member function
void OLEDFont_contructor(OLEDFont *this, Storage *storage);

static inline uint8_t OLEDFont_getDotMatrix(const OLEDFont *this, uint8_t *dotMatrix,
                                            const uint8_t *font, const uint8_t fontSize) {
    return this->vptr->get_font_dot_matrix(this, dotMatrix, font, fontSize);
}


#define ENCODING_GBK        0
#define ENCODING_UTF8       1

/**
 * ASCII has 95 displayable character.
 * --------------------------------------------------------------------------------------
 * | Height * Width | display pixel | Graphic Memory(PAGE x SEG) | Bytes | font library |
 * |----------------|---------------|----------------------------|-------|--------------|
 * |    12 *  6     |   12 *  6     |          2 *  6            |  12   | 12*95=0x474  |
 * |    16 *  8     |   16 *  8     |          2 *  8            |  16   | 16*95=0x5F0  |
 * |    24 * 12     |   24 * 12     |          3 * 12            |  36   | 36*95=0xD5C  |
 * |------------------------------------------------------------------------------------|
 *
 * total 0x17C0(6080) bytes, about 6KB.
 */
#define STORAGE_ASCII_12X6_ADDRESS              0x00000000
#define STORAGE_ASCII_16X8_ADDRESS              0x00000000
#define STORAGE_ASCII_24X12_ADDRESS             0x00000000

/**
 * generate in range 0x4E00 ~ 0x9FFF from UNICODE
 */
#define STORAGE_UNICODE_CN_ZH_12X12_ADDRESS     0x0055C000  // 1476k ~ 1500k
#define STORAGE_UNICODE_CN_ZH_16X16_ADDRESS     0x005D9000  // 656k ~ 700k
#define STORAGE_UNICODE_CN_ZH_24X24_ADDRESS     0x00688000  // 492k ~ 500k

/**
 * generate in range 0x ~ 0x from gbk
 */
#define STORAGE_GBK_12X12_ADDRESS               0x00142000  // 755k ~ 800k
#define STORAGE_GBK_16X16_ADDRESS               0x0020A000  // 1006k ~ 1100k
#define STORAGE_GBK_24X24_ADDRESS               0x0031D000  // 2264k ~ 2300k

#endif //JLC_SKY_OLED_FONT_H
